<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<style>
.answer ul {list-style: none}
</style>
<div class="middle padtop10 myclear">
	<div class="page-content">
		
		<!-- bread crumb -->
		<p id="bread-crumb">
			<a href="<?php echo base_url();?>">
				<?php echo $lang['home']?>
			</a>
			<a href="<?php echo site_url('faqs');?>">
				<?php echo $lang['faqs'];?>
			</a>
			<?php echo $lang['faqs'];?>
		</p>
		<!-- end bread crumb -->
		<h3>
			<?php echo $lang['faqs'];?>
		</h3>
		<br style="clear:both;" />
		<table width="100%">
			<tr>
				<td width="250px">
					<?php echo $lang['category']?>:
					<select id="lstCategory" style="width:200px" onchange="changeCat();">
						<option value="0"><?php echo $lang['select_all'];?></option>
						<?php foreach ($lstCat as $item){?>
						<option value="<?php echo $item->cat_id;?>" <?php if($cat == $item->cat_id) echo 'selected="selected"'?>>
							<?php echo ($item->parent_id > 0 ? '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|_' : '').$item->name;?>
						</option>
						<?php }?>
					</select>
				</td>
				<td style="text-align:right">
					<input type="button" value="<?php echo $lang['add'];?>" onclick="window.location.href='<?php echo site_url('faqs/addTopic');?>';" />
					&nbsp;|&nbsp;
					<input type="button" value="<?php echo $lang['manager_category'];?>" onclick="window.location.href='<?php echo site_url('faqs/Categories');?>';" />
				</td>
			</tr>
		</table>
		<br />
		<table class="tbl-list" width="100%" border="1">
			<tr>
				<td width="4%" class="td-label" style="text-align:center">
					<b>#</b>
				</td>
				<td class="td-label">
					<b><?php echo $lang['topic'];?></b>
				</td>
			</tr>
			<?php $i = 0; foreach ($topics as $item){ $i++; ?>
			<tr class="row">
				<td style="text-align:center">
					<?php echo ($i + $stt);?>
				</td>
                <td>
                	<img src="<?php echo base_url();?>/images/icon_expand.gif" border="0" style="vertical-align:middle" />&nbsp;
					<a href="javascript:void(0);" onclick="getAnswer(this,<?php echo $item->id;?>);">
						<?php echo $item->content;?>
					</a>&nbsp;...
					<a href="<?php echo site_url('faqs/addTopic/?id='.$item->id);?>">
						[<?php echo $lang['edit'];?>]
					</a>
					<div class="answer t<?php echo $item->id;?>"></div>
				</td>
			</tr>
			<?php }?>
		</table>
        <!-- paging -->
        <div class="myclear martop20">
            <div class="brv-paging-left">
                <table class="tbl-list brv-paging" border="1">
                    <tr>
                        <td class="brv-paging-name">
                            <?php echo $lang['page'].' '. $page.' ['.$pages.']'?>
                        </td>
                        
                        <td class="brv-paging-pre-next">
                            <img class="brv-img-pre" alt="previous" src="/images/imgpre.gif" onclick="goPage(<?php echo $page > 1 ? $page - 1 : $page;?>)" />
                            <img class="brv-img-next" alt="next" src="/images/imgnext.gif" onclick="goPage(<?php echo $page < $pages ? $page + 1 : $page;?>)" />
                        </td>
                    </tr>
                </table>
            </div>
            <!-- important. fix for ie 6. Don't remove -->
            <!--[if IE 6]><br class="clearboth" /><![endif]-->
        </div>
        <!-- end paging -->
	</div>
</div><br />
<script type="text/javascript">
$(document).ready(function(){
	$('.tbl-list .row').mouseover(function(){
		$(this).css('background','#ffc');
	});
	$('.tbl-list .row').mouseout(function(){
		$(this).css('background','none');
	});
});
function goPage(strVal)
{
	var cat = $('#lstCategory').val();
	window.location.href = '<?php echo site_url('faqs');?>/?cat='+cat+'&page=' + strVal;
}
function changeCat()
{
	var cat = $('#lstCategory').val();
	window.location.href = '<?php echo site_url('faqs');?>/?cat='+cat;
}
function getAnswer(obj,topic)
{
	if($.trim($('.answer.t'+topic).html()) != '')
	{
		if($('.answer.t'+topic).css('display') == 'none')
		{
			$(obj).prev('img').attr('src', '<?php echo base_url();?>/images/icon_collapse.gif');
			$('.answer.t'+topic).show();
		}
		else
		{
			$(obj).prev('img').attr('src', '<?php echo base_url();?>/images/icon_expand.gif');
			$('.answer.t'+topic).hide();
		}
	}
	else
	{
		$('.answer.t'+topic).html('<img src="/images/ajaxLoading.gif" border="0" />');
		$.ajax({
			url: '<?php echo site_url('faqs/getTopic')?>/?parent='+topic,
			success: function(data){
				$(obj).prev('img').attr('src', '<?php echo base_url();?>/images/icon_collapse.gif');
				$('.answer.t'+topic).html(data);
			}
		});
	}
}
</script>